<?php
namespace app\admin\controller;
use think\Controller;

class Login extends Controller
{
    /**
     * 登陆页
     * @return \think\response\View
     */
     public function index()
     {
        return view();
     }

    /**
     * 退出登陆
     */
    public function logout()
    {
        session(null);
        $this->redirect('login/index');
    }

    /**
     * 登陆处理
     * @return \think\response\Json
     */
    public function login()
    {
        $data = input();
        $user = D('account');
        $where['enable']=2;
        $where['account']=$data['user_name'];
        $where['passwd']=md5(md5($data['password']).config("keys"));
        $res = $user->where($where)->find();
        if(!$res){
            return ['flag'=>-1,'msg'=>'用户名或密码错误'];
        }
        session("userId",$res['id']);
        return ['flag'=>0,'msg'=>'登陆成功'];
    }
}